<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>用户登录 - 回声网络</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <style>
        body {
            margin: 0;
            padding: 0;
            background: #f5f5f5;
            font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
        }
    </style>
</head>
<body>
<div id="app">
    <el-card style="width: 400px;">
        <div slot="header">
            <span style="font-size: 18px; font-weight: bold;">用户登录</span>
        </div>

        <el-form :model="form" :rules="rules" ref="form">
            <el-form-item prop="username">
                <el-input v-model="form.username" placeholder="请输入用户名" prefix-icon="el-icon-user"></el-input>
            </el-form-item>

            <el-form-item prop="password">
                <el-input type="password" v-model="form.password" placeholder="请输入密码" prefix-icon="el-icon-lock" show-password @keyup.enter.native="submitForm"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" style="width: 100%;" @click="submitForm">登录</el-button>
            </el-form-item>
        </el-form>

        <div style="text-align: center; margin-top: 20px;">
            <el-link type="primary" href="register.html">没有账号？立即注册</el-link>
        </div>
    </el-card>
</div>

<script src="https://unpkg.com/vue@2/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
    new Vue({
        el: '#app',
        data: {
            form: {
                username: '',
                password: ''
            },
            rules: {
                username: [
                    { required: true, message: '请输入用户名', trigger: 'blur' }
                ],
                password: [
                    { required: true, message: '请输入密码', trigger: 'blur' }
                ]
            }
        },
        methods: {
            submitForm() {
                this.$refs.form.validate((valid) => {
                    if (valid) {
                        const form = document.createElement('form');
                        form.method = 'POST';
                        form.action = 'login';
                        form.style.display = 'none';

                        ['username', 'password'].forEach(field => {
                            const input = document.createElement('input');
                            input.name = field;
                            input.value = this.form[field];
                            form.appendChild(input);
                        });

                        document.body.appendChild(form);
                        form.submit();
                    }
                });
            }
        }
    });
</script>
</body>
</html>